package pk.nak.adapters;

import java.util.ArrayList;

import pk.nak.data.EatOutMenuItemPriceGroup;
import pk.nak.client.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PriceComparatorAdapter extends ArrayAdapter<EatOutMenuItemPriceGroup> {
	private ArrayList<EatOutMenuItemPriceGroup> items;

	public PriceComparatorAdapter(Context context, int textViewResourceId,
			ArrayList<EatOutMenuItemPriceGroup> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.items = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		if ( v == null ){
			LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.eatoutpricecomparerow, null);
		}
		
		EatOutMenuItemPriceGroup eomipg = this.items.get(position);
		
		if ( eomipg != null ){
			TextView tvName = (TextView) v.findViewById(R.id.tvMenuItemName);
			TextView tvPrice = (TextView) v.findViewById(R.id.tvMenuItemPrice);
			
			if ( tvName != null ) tvName.setText(eomipg.getEatout().getEatoutName());
			if ( tvPrice != null ) tvPrice.setText(""+eomipg.getPrice());
		}
		
		return v;
	}
}
